<?php

namespace App\Services\Mission;

use App\Constants\MissionType;
use App\Dao\MissionConfigDao;
use App\Model\User;

class MissionQueueService
{
    private MissionService $service;

    public function __construct()
    {
        $this->service = new MissionService();
    }

    public function sex($uid)
    {
        return User::query()->where('id', $uid)->value('sex') ?? 0;
    }


    /**
     * Note - 拨打视频任务
     * DateTime 2024/8/2 12:08
     * User Admin
     * @param $uid
     * @param $sex
     * @return bool
     */
    public function archiveCallMission($uid, $sex = null)
    {
        $sex = User::query()->where('id', $uid)->value('sex');
        if ($sex != 1 && $sex != 2) {
            return false;
        }
        return $this->service->archiveMission($uid, ($sex == 1) ? MissionType::MALE_CALL : MissionType::FEMALE_CALL);
    }


    /**
     * Note - 评论任务
     * DateTime 2024/8/2 12:08
     * User Admin
     * @param $uid
     * @param $sex
     * @return bool
     */
    public function archiveCommentMission($uid, $sex = null)
    {
        $sex = User::query()->where('id', $uid)->value('sex');
        return ($sex == 1) && $this->service->archiveMission($uid, MissionType::MALE_COMMENT);
    }


    /**
     * Note - 点赞任务
     * DateTime 2024/8/2 12:09
     * User Admin
     * @param $uid
     * @param $sex
     * @return bool
     */
    public function archiveLikeMission($uid, $sex)
    {
        return ($sex == 1) && $this->service->archiveMission($uid, MissionType::MALE_LIKE);
    }


    /**
     * Note - 修改个人信息任务
     * DateTime 2024/8/2 18:46
     * User Admin
     * @param $uid
     * @param $sex
     * @return bool
     */
    public function archiveProfileMission($uid, $flag)
    {
        $sex = User::query()->where('id', $uid)->value('sex');
        $mission = ($sex == 1) ? MissionType::MALE_PROFILE : MissionType::FEMALE_PROFILE;
        return $this->service->archiveMission($uid, $mission, $flag);
    }


    /**
     * Note - 拨打音频任务，仅男用户可触发
     * DateTime 2024/8/2 12:10
     * User Admin
     * @param $uid
     * @param $sex
     * @return mixed
     */
    public function archiveAudioMission($uid, $sex)
    {
        $sex = User::query()->where('id', $uid)->value('sex');
        return ($sex == 1) && $this->service->archiveMission($uid, MissionType::MALE_AUDIO);
    }


    /**
     * Note - 发帖任务
     * DateTime 2024/8/2 12:09
     * User Admin
     * @param $uid
     * @param $sex
     * @return bool
     */
    public function archiveTopicMission($uid, $sex)
    {
        if ($sex != 1 && $sex != 2) {
            return false;
        }

        return ($sex == 1)
            ? $this->service->archiveMission($uid, MissionType::MALE_TOPIC)
            : $this->service->archiveMission($uid, MissionType::FEMALE_TOPIC);
    }


    /**
     * Note - 回复消息成功任务
     * DateTime 2024/8/9 12:42
     * User Admin
     * @param $uid
     * @return bool
     */
    public function archiveReplyMission($uid)
    {
        $sex = self::sex($uid);
        return ($sex == 1) && $this->service->archiveMission($uid, MissionType::MALE_REPLY);
    }

    /**
     * Note -  teaser任务
     * DateTime 2024/8/14 17:54
     * User Admin
     * @param $uid
     * @param $sex
     * @return bool|int
     */
    public function archiveTeaseMission($uid, $sex)
    {
        // $model = new MissionModel();
        return ($sex == 1) && $this->service->archiveMission($uid, MissionType::MALE_TEASE);
    }


}